# coding =UTF-8
'''
公用工具
'''
import os, re, sys


def getIPv4():
    '''
    获取本机的IPv4地址
    :return:
    '''
    str = os.popen("ipconfig").read()
    ip = re.search(r'IPv4 地址 . . . . . . . . . . . . : \S*', str).group().split(':')[1].strip(' ')
    return ip


def print_exception(func):
    def wrapper(*args, **kwargs):
        '''
        异常捕捉装饰器
        :param func:
        :return:
        '''
        try:
            res = func(*args, **kwargs)
            return res
        except Exception as e:
            print(f'ERROR : {e}')
            # sys.exit(1)
        # return res
    return wrapper


def pro_path(filename='my_test'):
    '''
    获取当前项目路径
    :param filename:
    :return: */my_test
    '''
    dirpath = os.path.abspath('.')
    path = dirpath[:dirpath.find(filename)] + filename
    return path
